<?php require_once("php/dates.php");?>
<h3>Latest Activity</h3>

<ul id="latest_activity">
<?php 
if($activity):
foreach($activity as $event):
if($i++>=100)
	break;
?>
<li>
	<img  class="photo" src="http://www.gravatar.com/avatar/<?php echo md5( strtolower( trim($event['email']) ) );?>" width=40 height=40 title="<?php echo $event['email'];?>" />
    <span class="timestamp">
		<?php echo TimeAgo($event['timestamp']);?>
    </span>
    <span class="desc"><a href="user-recipe.php?author=<?php echo $event['id'];?>&nickname=<?php echo $event['nickname'];?>&email=<?php echo $event['email'];?>"><?php echo $event['nickname'];?></a>
    <?php switch($event['type']){
		case "recipe":
			?>posted a new recipe.</span>
            <table>
            	<tr>
                	<td>
						<div class="recipe_mask">
                        <a href="view-recipe.php?rid=<?php echo $event['rid'];?>">
                        	<img src="php/photo.php?recipe_id=<?php echo $event['rid'];?>" title="<?php echo $event['name'];?>" />
                        </a>
                        </div>
                    </td>
                    <td>
                    	<a href="view-recipe.php?rid=<?php echo $event['rid'];?>"><h5><?php echo $event['name'];?></h5></a>
                        <?php foreach($event['tags'] as $tag):
                        	?><a href="tag-recipe.php?tag=<?php echo $tag['name'];?>&tid=<?php echo $tag['id'];?>"><span class='tag'><?php echo $tag['name'];?></span></a><?php
                       	endforeach;?>
                    </td>
                </tr>
            </table>
			<?php
		break; // recipe
		case "favorite":
			?>added a new favorite recipe.</span>
            <table>
            	<tr>
                	<td>
						<div class="recipe_mask">
                        <a href="view-recipe.php?rid=<?php echo $event['rid'];?>">
                        	<img src="php/photo.php?recipe_id=<?php echo $event['rid'];?>" title="<?php echo $event['name'];?>" />
                        </a>
                        </div>
                    </td>
                    <td>
                    	<a href="view-recipe.php?rid=<?php echo $event['rid'];?>"><h5><?php echo $event['name'];?></h5></a>
                        <?php foreach($event['tags'] as $tag):
                        	?><a href="tag-recipe.php?tag=<?php echo $tag['name'];?>&tid=<?php echo $tag['id'];?>"><span class='tag'><?php echo $tag['name'];?></span></a><?php
                       	endforeach;?>
                    </td>
                </tr>
            </table>
			<?php
		break; // favorite
		case "comment";
			?>commented on <a href="view-recipe.php?rid=<?php echo $event['rid'];?>"><?php echo $event['name'];?></a>,</span>
            <table>
            	<tr>
                	<td>
					"<span class="comment"><?php echo $event['comment'];?></span>"
                    </td>
                </tr>
            </table>
            <?php
		break; // comment
		case "rating";
			?>rated <a href="view-recipe.php?rid=<?php echo $event['rid'];?>"><?php echo $event['name'];?></a> <span class="rating"><b><?php echo $event['rating'];?></b> out of 5 stars</span>.</span>
            <table>
            	<tr>
                	<td>
						<div class="recipe_mask">
                        <a href="view-recipe.php?rid=<?php echo $event['rid'];?>">
                        	<img src="php/photo.php?recipe_id=<?php echo $event['rid'];?>" title="<?php echo $event['name'];?>" />
                        </a>
                        </div>
                    </td>
                    <td>
                    	<a href="view-recipe.php?rid=<?php echo $event['rid'];?>"><h5><?php echo $event['name'];?></h5></a>
                        <?php for($i=0; $i<$event['avg_rating']; $i++):
                        echo "<img src='images/star-on.png' />";
                        endfor;?>
                        <span class="avg_rating">
                        <?php echo $event['rating_count'];
						if($event['rating_count']!=1):
						echo " ratings";
						else:
						echo " rating";
						endif;?>
                        </span>
                    </td>
                </tr>
            </table>
            <?php
		break; // rating
		default:
			echo "</span>";
	}// end switch?>
</li>
<?php
endforeach;
else:
	echo "No activity to display.";
	$no_activity = true;
endif;
?>
</ul>

<script>
resize(".recipe_mask img",75,75);
</script>